package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.R
import com.erp.bean.PieceworkcollBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.dialog_mydialog.view.view
import kotlinx.android.synthetic.main.lv_piecework_grouping.view.*

class PieceworkcollAdapter(private val mlist: List<PieceworkcollBean>, private val mcontext: Context) : BaseAdapter(){
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)


    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        val h: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_piecework_grouping, null)
            h = ViewHolder(v)
            v.tag = h
        } else {
            v=convertView
            h = convertView.tag as ViewHolder
        }
        var bean = mlist[position]
        Myutil.settv("岗位："+bean.gangwei_name,h.TvGangwei)
        Myutil.settv("项目："+bean.xm,h.TvXiangmu)
        Myutil.settv("创建时间："+bean.created_at,h.TvCreatedAt)
        Myutil.settv("采集人："+bean.creator_name,h.TvCreatorName)
        Myutil.settv("成员："+bean.worker_group,h.TvWorkerGroup)
        Myutil.settv("采集内容："+bean.qr_content,h.TvQrContent)
        Myutil.settv("采集说明："+bean.content_cat,h.TvContentCat)
        if(bean.batch_names != null){
            Myutil.settv("节号："+bean.batch_names,h.TvBatchNames)
            h.TvBatchNames.visibility = View.VISIBLE
        }else{
            h.TvBatchNames.visibility = View.GONE
        }
        if(bean.square != ""){
            Myutil.settv("平方："+bean.square,h.TvSquare)
            h.TvSquare.visibility = View.VISIBLE
        }else{
            h.TvSquare.visibility = View.GONE
        }
        if(bean.pcount != ""){
            Myutil.settv("包数："+bean.pcount,h.TvPcount)
            h.TvPcount.visibility = View.VISIBLE
        }else{
            h.TvPcount.visibility = View.GONE
        }
        if(bean.mcount != ""){
            Myutil.settv("件数："+bean.mcount,h.TvMcount)
            h.TvMcount.visibility = View.VISIBLE
        }else{
            h.TvMcount.visibility = View.GONE
        }
        return  v;
    }

    internal class ViewHolder(v: View) {
        var TvGangwei: TextView
        var TvXiangmu: TextView
        var TvCreatedAt: TextView
        var TvCreatorName: TextView
        var TvWorkerGroup: TextView
        var TvQrContent: TextView
        var TvContentCat: TextView
        var TvBatchNames: TextView
        var TvSquare: TextView
        var TvPcount: TextView
        var TvMcount: TextView
        init {
            TvGangwei = v.TvGangwei
            TvXiangmu = v.TvXiangmu
            TvCreatedAt = v.TvCreatedAt
            TvCreatorName = v.TvCreatorName
            TvWorkerGroup = v.TvWorkerGroup
            TvQrContent = v.TvQrContent
            TvContentCat = v.TvContentCat
            TvBatchNames = v.TvBatchNames
            TvSquare = v.TvSquare
            TvPcount = v.TvPcount
            TvMcount = v.TvMcount
        }
    }
}